import Vue from 'vue'
import Router from 'vue-router'
import '@/assets/js/rem.js'
import '@/assets/js/dingtalk.js'
const Login = () => import('@/pages/Login/Login')
const Home = () => import('@/pages/Home/Home')
const RuningWater = () => import('@/components/runingWater/runningWater')
const DriverNumber = () => import('@/components/driverNumber/driverNumber')
const Passenger = () => import('@/components/passenger/passenger')
const Circuit = () => import('@/components/circuit/circuit')
const Attention = () => import('@/pages/Attention/attention')
const My = () => import('@/pages/My/my')
const HotPic = () => import('@/pages/HotPic/hotPic')
const HotPicPassenger = () => import('@/pages/HotPicPassenger/hotPicPassenger')
const AboutUs = () => import('@/pages/AboutUs/aboutUs')
const RepeatPassword = () => import('@/pages/RepeatPassword/repeatPassword')
const ListDetail = () => import('@/components/ListDetail/ListDetail')
const List = () => import('@/components/List/List')
Vue.use(Router)

const router = new Router({
  /*  mode: 'history', */
  linkExactActiveClass: 'active',
  routes: [{
    path: '/',
    name: 'login',
    component: Login,
    meta: {
      title: '登录'
    }
  },
  {
    path: '/home/:id',
    component: Home,
    children: [{
      path: '',
      name: 'runingWater',
      component: RuningWater,
      meta: {
        title: '首页'
      }
    },
    {
      path: 'driverNumber',
      name: 'driverNumber',
      component: DriverNumber,
      meta: {
        title: '首页'
      }
    },
    {
      path: 'passenger',
      name: 'passenger',
      component: Passenger,
      meta: {
        title: '首页'
      }
    },
    {
      path: 'circuit',
      name: 'circuit',
      component: Circuit,
      meta: {
        title: '首页'
      }
    }

    ]
  },
  {
    path: '/hotPic/:id',
    component: HotPic,
    children: [
      {
        path: '',
        component: HotPicPassenger,
        meta: {
          title: '热力图'
        }
      }
    ]
  },
  {
    path: '/attention',
    component: Attention,
    meta: {
      title: '关注'
    }
  },
  {
    path: '/my',
    component: My,
    meta: {
      title: '我的'
    }
  },
  {
    path: '/aboutUs',
    component: AboutUs,
    meta: {
      title: '关于我们'
    }
  },
  {
    path: '/repeatPassword',
    component: RepeatPassword,
    meta: {
      title: '修改密码'
    }
  },
  {
    path: '/listDetail',
    component: ListDetail,
    meta: {
      title: '详情'
    }
  },
  {
    path: '/list',
    component: List,
    meta: {
      title: '列表'
    }
  }

  ]
})
// 设置页面标题//并判断是否登录
router.beforeEach((to, from, next) => {
  const isLogin = sessionStorage.getItem('token')
  console.log(isLogin)
  document.title = to.meta.title
  const nextRoute = [ 'runingWater', 'driverNumber', 'passenger', 'circuit' ]
  if (nextRoute.indexOf(to.name) >= 0) {
    // 未登录
    if (isLogin == null) {
      router.push({ name: 'login' })
    }
  }

  next()
})
export default router
